//
//  YLAccountTool.m
//  YLFinanceService
//
//  Created by she1323 on 2017/8/23.
//  Copyright © 2017年 she1323. All rights reserved.
//

#import "YLAccountTool.h"
#import "YLPushViewModel.h"

#define YLAccountPath [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"account.archive"]

@implementation YLAccountTool


+ (void)saveAccount:(YLAccount *)account
{
    [NSKeyedArchiver archiveRootObject:account toFile:YLAccountPath];
}

+ (YLAccount *)account
{
    return [NSKeyedUnarchiver unarchiveObjectWithFile:YLAccountPath];
}

+ (void)noAccount
{
    [YLPushViewModel clearPushInfo];
    
    NSFileManager *manager = [NSFileManager defaultManager];
    [manager removeItemAtPath:YLAccountPath error:nil];
}

+ (NSDictionary *)header
{
    if (![YLAccountTool account]) {
        return nil;
    }
    return @{@"Authorization" : [YLAccountTool account].token};
}

@end
